// 获得注册按钮
var reBtn = document.getElementById("Register");



reBtn.addEventListener("click",function(){
    let data2 = new FormData();
    //利用构造函数创建一个对象存输入的账号密码
    data2.append("username", document.getElementById('re_username').value);
    data2.append("password", document.getElementById('re_password').value);
    data2.append("name", document.getElementById('re_name').value);
    data2.append("phone", document.getElementById('re_phone').value);
    
    //解决IE5 6 兼容性
    if(window.XMLHttpRequest){

        let xhr2 = new XMLHttpRequest();


        xhr2.open("POST",baseURL + "register",true);
        //设置请求类型初始化

        xhr2.send(data2);
        //发送输入的账号和密码

        xhr2.onreadystatechange = function(){
            if(xhr2.readyState === 4){
                if(xhr2.status === 200){
                    let info = JSON.parse(xhr2.responseText) 
                    //用info接受接口的数据
                    if(info.code === 200){

                        console.log(info.msg);
                        console.log(info);
                        alert("创建账户成功")
                    }
                    else{
                      alert("账户已存在");
                      console.log(info.msg);
                        console.log(info);
                    }
                }      
            }
        }


    }
    else{
        let xhr2 = new XMLHttpRequest();

        xhr2.open("POST",baseURL + "register",true);
        //设置请求类型初始化

        xhr2.send(data2);
        //发送输入的账号和密码

        xhr2.onreadystatechange = function(){
            if(xhr2.readyState === 4){
                if(xhr2.status === 200){
                    let info = xhr2.responseText;
                    //用info接受接口的数据
                    if(xhr2.code === 200){
                        console.log(info.msg);
                        alert("账号创建正确");
                      
                    }
                    else{
                        console.log(info.msg);
                        alert("账户已存在");
                    }
                }      
            }
        }


    }
}) 